/*******************************************************************************
  * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.   
  * @file     tftlcd.h
  * @author   UartTFT Application Team
  * @version  V0.0.1
  * @date     2023-01-09
  * @brief    This file contains the interface initialization and basic
  *           control functions of the TFT.
********************************************************************************/ 

#ifndef _TFTLCD_H
#define _TFTLCD_H

#include "data.h"
//#include "eport_drv.h"
//#include "spi_drv.h"
//#include "pwm_drv.h"

//----------------------LCD_SPI_Port------------------------------
#define LT_TFTSPI_DMA   2             // 1:DMA  2:EDMA

//----------------------LCD_PPI------------------------------


#define  LCD_RST_RESET   EPORT0->EPDR &=~(1<<3)
#define  LCD_RST_SET     EPORT0->EPDR |= (1<<3)

#define  LCD_CS_RESET
#define  LCD_CS_SET

#define  LCD_RS_CMD
#define  LCD_RS_DATA

#define  LCD_RD_RESET
#define  LCD_RD_SET

#define  LCD_WR_RESET
#define  LCD_WR_SET

#define  LCD_WR_READ_L
#define  LCD_WR_READ_H
#define  LCD_WR_WRITE

	


#define  LCD_DATA_WRITE_H  EPORT3->EPDR           //Write
#define  LCD_DATA_WRITE_L  EPORT->EPDR            //Write

#define  LCD_DATA_READ_L  EPORT->EPPDR           //Read

#define LCD_PIN_OUTPUT    \
  {                       \
    EPORT3->EPDDR = 0xff; \
    EPORT->EPDDR = 0xff;  \
  }
#define LCD_PIN_INPUT     \
  {                       \
    EPORT3->EPDDR = 0x00; \
    EPORT->EPDDR = 0x00;  \
  }



#define CS_ST77903_L   CCM->QSPIGPIOCR &= ~(0x400)
#define CS_ST77903_H   CCM->QSPIGPIOCR |=  (0x400)
#define QSPI2_TFT_MAXSIZE	326400	// 400*400*2 = 320000
#define TFT_QSPI_DIV	4			//200Mhz/4 = 50Mhz
extern uint8_t qspi_tft_buf[QSPI2_TFT_MAXSIZE];
extern uint32_t QSPI_BUFF_START[];
extern uint16_t pit_urow;
extern uint8_t pit_uflag;
void TFT_QSPI_screen_init(void);
void TFT_QSPI_Quad_Init(void);
void TFT_QSPI_Quad_DMA_Porch(uint8_t command_bits, uint8_t addr_bits, uint8_t dummy_bits, uint32_t addr, uint32_t num, uint8_t* buf);
void TFT_QSPI_Quad_DMA_Line(uint8_t command_bits, uint8_t addr_bits, uint8_t dummy_bits, uint32_t addr, uint32_t num, uint8_t* buf);
void QSPI1_QSPI2_Priority_Set(void);

void LCD_RS(uint8_t bit);
void LCD_CS(uint8_t bit);

//LCD_SPI
void LCD_SPI_Port_Init(void);
uint8_t LCD_SPI_ReadWriteByte(uint8_t Send);
void LCD_SPI_WriteData_DMA(uint8_t *Tx_Addr,uint32_t length);
void LCD_SPI_WriteData_EDMA(uint8_t *Tx_Addr, uint32_t length,uint8_t inc);

//LCD_PPI

void TFT_CommandWrite(uint8_t cmd);
void TFT_DataWrite(uint8_t data);
void TFT_DataWrite_DMA(uint16_t *buf,uint16_t len);

//LCD_Init
void LCD_TFT_Init(void);
void LT268_TFT_SetWindows(uint16_t XStar,uint16_t yStar,uint16_t Width,uint16_t High);

void ST7789VPanelSleepInMode(void);
void ST7789VPanelSleepOutMode(void);
void LT268_Display_ON(void);
void LT268_Display_OFF(void);



#endif	/* _TFTLCD_H */
